package com.pc.service.serviceImpl;

import com.pc.common.Result;
import com.pc.model.Student;
import com.pc.service.IStudentService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class StudentServiceImpl implements IStudentService {

    @Value("${server.port}")
    String port;
    @Override
    public String getStudent() {
        System.out.println(port);
        return "张三";
    }

    @Override
    public Result getAllStudent() {
        System.out.println(port);
        List<Student> students = new ArrayList<>();
        students.add(Student.builder().id(1L).status(1).studentName("袁冒").createTime(new Date()).build());
        students.add(Student.builder().id(2L).status(1).studentName("芝麻酱").createTime(new Date()).build());
        students.add(Student.builder().id(3L).status(1).studentName("醉了").createTime(new Date()).build());
        students.add(Student.builder().id(4L).status(1).studentName("憨包").createTime(new Date()).build());

        return Result.success(students);
    }

    @Override
    public Result getStudentById(Long id) {
        System.out.println(port);
        List<Student> students = new ArrayList<>();
        students.add(Student.builder().id(1L).status(1).studentName("袁冒").createTime(new Date()).build());
        students.add(Student.builder().id(2L).status(1).studentName("芝麻酱").createTime(new Date()).build());
        students.add(Student.builder().id(3L).status(1).studentName("醉了").createTime(new Date()).build());
        students.add(Student.builder().id(4L).status(1).studentName("憨包").createTime(new Date()).build());
        Student student = students.stream().filter(x -> {
            if (x.getId().equals(id)) {
                return true;
            }
            return false;
        }).findFirst().orElse(null);
        return Result.success(student);
    }
}
